package com.dikang.keer.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.dikang.common.utils.PageUtils;
import com.dikang.common.utils.R;
import com.dikang.keer.product.vo.AttrRespVo;
import com.dikang.keer.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dikang.keer.product.service.AttrService;


/**
 * 商品属性
 *
 * @author stbz
 * @email 1287796639@qq.com
 * @date 2021-10-21 02:01:46
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
        AttrRespVo attrRespVo = attrService.getAttrRespVo(attrId);
    System.out.println(attrRespVo);
        return R.ok().put("attrGroup", attrRespVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody AttrVo attr){
         System.out.println(attr);
		attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }
    @RequestMapping("/{attrType}/list/{catelogId}")
    public  R baseList(@RequestParam Map<String, Object> params
            ,@PathVariable("catelogId") Long cateLogId
            ,@PathVariable("attrType") String attrType){
       PageUtils page =  attrService.queryBasePage(params,cateLogId,attrType);
        return R.ok().put("page", page);
    }



}
